import { Styles } from "./type";
import { isEmtyObject, isNumber, mergeObject, isString, transformUperCaseRow } from "./utils";
export let setRem = false
export let frontSize = 16
export enum defuatColor {
   primary = '#409EFF',
   success = '#67C23A',
   warnimg = '#E6A23C',
   danger = '#F56C6C',
   info = '#909399'
}
export function handleStyles(defuatStyle: Styles, customerStyle: Styles = {}) {
   if (!defuatStyle || isEmtyObject(defuatStyle)) {
      console.error('丢失默认属性')
   }
   const stylesObj = mergeObject(defuatStyle, customerStyle)
   return createStyleStr(stylesObj)
}

function createStyleStr(styles: object) {
   let res = ``
   for (let key in styles) {
      if (!isNumber(styles[key]) && !isString(styles[key])) {
         // 属性的值必须为字符串或者数字
         console.warn('请检查属性值')
      }
      res += `${transformUperCaseRow(key)}: ${handleStyleRow(styles[key], setRem)}`
   }
   return res
}
const handleStyleRow = (val: number | string, setRem: boolean) => {
   if (isNumber(val)) {
      return `${val}px;`
   }
   return val + ';'
}  